function Rectangle(name, width, height) {
  this.name = name;
  this.width = width;
  this.height = height;
  this.area = function () {
    return this.width * this.height;
  };
}
function Rectangle(name, width, height) {
  this.name = name;
  this.width = width;
  this.height = height;
}
// 将 `area` ⽅法添加到原型
 Rectangle.prototype.area = function () {
  return this.width * this.height;
 };
// const rect = new Rectangle("矩形 1", 10, 10);
// console.log(rect.area()); // 输出：100
// console.log(rect);
// // 输出：Rectangle { name: '矩形 1', width: 10, height: 10 }
// console.log(Object.getPrototypeOf(rect));
// // 输出：{ area: [Function: area]
// Rectangle.prototype.perimeter = function () {
//   return 2 * (this.width + this.height);
// };
// Rectangle.prototype.isSquare = function () {
//   return this.width === this.height;
// };
// Rectangle.prototype.changeName = function (newName) {
//   this.name = newName;
// };
const rect = new Rectangle("矩形 1", 10, 10);
console.log(rect.area()); // 输出：100
console.log(rect.perimeter()); // 输出：40
console.log(rect.isSquare()); // 输出：true
rect.changeName("测试矩形");
console.log(rect.name); // 输出：测试矩形






// const rect = new Rectangle('Rect', 10, 10);